package com.hanter.rad.pickerviewdemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.hanter.rad.widget.cupertino.PickerView;
import com.hanter.rad.widget.cupertino.PickerViewDataSource;
import com.hanter.rad.widget.cupertino.PickerViewDelegate;
import com.hanter.rad.widget.cupertino.utils.DatePickerFragment;
import com.hanter.rad.widget.cupertino.utils.OnDatePickerClickListener;
import com.hanter.rad.widget.cupertino.utils.PickerProvider;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;

public class MainActivity extends AppCompatActivity implements OnDatePickerClickListener, PickerProvider {

    private static final String TAG = "MainActivity";

    private Toast toast;

    private PickerView mPickerView;

    private ArrayList<String> list = new ArrayList<>();
    private ArrayList<String> list2 = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        for (int i = 0; i < 18; i++) {
            list.add("item gp" + i);
        }

        for (int i = 0; i < 10; i++) {
            list2.add("item " + i);
        }

        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                PickerFragment f = new PickerFragment();
//                f.show(getSupportFragmentManager(), "picker");
//
//                PickerDialog dialog = new PickerDialog();
//                dialog.show(getSupportFragmentManager(), "picker");


                DatePickerFragment f = new DatePickerFragment();
                f.show(getSupportFragmentManager(), "picker");

            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    public void onDatePickerCancel(String tag) {

    }

    @Override
    public void onDatePickerSelected(String tag, Date date) {
        Log.d(TAG, "onDatePickerSelected: " + date.toLocaleString());
    }

    @Override
    public PickerViewDataSource getDataSource(String tag) {
        return new PickerViewDataSource() {
            @Override
            public int getNumberOfComponentsInPickerView() {
                return 2;
            }

            @Override
            public int getNumberOfRowsInComponent(int component) {

                if (component == 0) {
                    return list.size();
                } else if (component == 1) {
                    return list2.size();
                } else {
                    return 0;
                }


            }
        };
    }

    @Override
    public PickerViewDelegate getDelegate(String tag) {
        return new PickerViewDelegate() {
            @Override
            public int getWidthForComponent(int component) {
                return 0;
            }

            @Override
            public int getRowHeightForComponent(int component) {
                return 0;
            }

            @Override
            public String getTitleForRow(int row, int component) {

                if (component == 0) {
                    return list.get(row);
                } else if (component == 1) {
                    return list2.get(row);
                } else {
                    return "";
                }
            }

            @Override
            public void didSelectRow(int row, int component) {

            }

            @Override
            public int getInitPositionInComponent(int component) {
                return 0;
            }
        };
    }
}
